package com.exit66.jukebox.servlet.xml;

import javax.servlet.http.HttpServletRequest;

import com.exit66.jukebox.DemoSoundPlayer;
import com.exit66.jukebox.SoundPlayer;
import com.exit66.jukebox.data.Track;
import com.exit66.jukebox.util.XmlSegment;
import com.exit66.jukebox.Options;

public class CurrentTrackServlet extends XmlResponseServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4613365287025702369L;

	protected void buildXml(HttpServletRequest req, XmlSegment xml) {
		
		Track track = new Track();
        if (!Options.inDemoMode())
            track.setTrackID(SoundPlayer.getSoundPlayer().currentTrackID);
        else
            track.setTrackID(DemoSoundPlayer.getSoundPlayer().currentTrackID);
		if (track.getTrackID() != -1) {
			track.fetch();
			xml.appendSegment(track.returnXml(true, true));
		}
	}
}
